package com.xzy.mybatis.cipher.support.strategy.crypto;

import cn.hutool.crypto.symmetric.AES;
import com.xzy.mybatis.cipher.support.enums.CryptoStrategyEnum;

import java.nio.charset.StandardCharsets;

/**
 * 对称加密：AES
 *
 * @author xzy.xiao
 * @since 2025/1/15  10:13
 */
public class AesCryptoStrategy extends CryptoStrategy {

    private final AES aes;

    public AesCryptoStrategy(String key) {
        super(key);
        this.aes = new AES(key.getBytes());
    }

    @Override
    public String getName() {
        return CryptoStrategyEnum.AES.getCode();
    }

    @Override
    public String encrypt(String value) {
        return aes.encryptBase64(value);
    }

    @Override
    public String decrypt(String value) {
        return aes.decryptStr(value, StandardCharsets.UTF_8);
    }
}
